package selcoursesys.service.impl;

import selcoursesys.entity.StudentInfo;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Lpbdz on 2017/4/12.
 */
public class SaveFile {
    public static void saveFile(List<StudentInfo> studentInfos){
        //studentInfos.add(new StudentInfo(studentEntity.getStuid(),studentEntity.getStuname() ,
        // studentEntity.getAcademyByAid().getAname(),studentEntity.getClazzByClassid().getClassname()));
        try{
            File file=new File("O:\\迅雷下载\\arshost-testjsp-master\\selectCourseSystem\\src\\main\\webapp\\upload\\data.csv");
            if(!file.exists()) {
                try {
                    System.out.println("123");
                    file.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            //System.out.println("当前路径"+request.getContextPath());
            FileOutputStream ost=new FileOutputStream("O:\\迅雷下载\\arshost-testjsp-master\\selectCourseSystem\\src\\main\\webapp\\upload\\data.csv");
            OutputStreamWriter out=new OutputStreamWriter(ost,"gbk");
            Iterator iterator=studentInfos.iterator();
            String message="";
            while(iterator.hasNext()){
                StudentInfo studentInfo=(StudentInfo)iterator.next();
                message=message+studentInfo.getStuid()+","+studentInfo.getStuname()+","+studentInfo.getAnum()+","+studentInfo.getSclass()+"\n";
            }
            out.write(message);
            //System.out.println("123456");
            out.close();
        }catch (Exception e){
            e.printStackTrace();
        }finally {

        }
    }
}
